package com.telnetnz.ticketdesk.action.base;

import org.apache.log4j.Logger;

import com.rockbb.common.sso.session.SessionConstants;
import com.telnetnz.ticketdesk.bean.User;
import com.telnetnz.ticketdesk.bean.misc.JsonMessage;
import com.telnetnz.ticketdesk.service.UserService;

public class BasicSessionLogAction extends BasicSessionAction
{
	private static Logger logger = Logger.getLogger(BasicSessionLogAction.class);

	public String intercepters()
	{
		String result = super.intercepters();
		if (result == null || result.equals(SUCCESS))
		{
			User user = getSessionUser();

			if (user.getId() == SessionConstants.USER_ID_ANONYMOUS
					|| user.getStatus() == UserService.USER_STATUS_INACTIVATED)
			{
				String jsoncallback = getRequest().getParameter("jsoncallback");
				JsonMessage message = new JsonMessage();
				message.setResult(JsonMessage.RESULT_ERROR);
				message.put_message("title", langRes.get("user.need-register-or-login"));
				message.put_message("explain", 
						langRes.get("user.need-register-or-login-message-json", new String[]{baseLink("userlogin", null, true)}));
				set_json_obj(message, jsoncallback);
				return JSON_ERROR;
			}
		}
		return result;
	}
}
